﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
using System.Data;
using System.Collections;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.Controls
{
    public partial class ProvinceCombo : System.Web.UI.UserControl
    {
        private IMasProvinceBLL BLL = new MasProvinceBLL();
        private IMasDistrictBLL disBLL = new MasDistrictBLL();
        public RadComboBox ctrChild;
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public void ListProvinceComboBox()
        {
            ListProvinceComboBox("");
        }
        public void ListProvinceComboBox(string Regions)
        {
            IList<MasProvinceInfo> InfoList = BLL.ListMasProvinces("", Regions);

            cbProvince.DataSource = InfoList;
            cbProvince.DataBind();
        }
        protected void cbProvince_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            if (cbProvince.SelectedValue.Length > 0)
            {
                IList<MasDistrictInfo> InfoList = disBLL.ListDistricts("", "", cbProvince.SelectedValue.ToString());
                
                if (ctrChild != null)               
                {
                    ctrChild.Items.Clear();

                    foreach (MasDistrictInfo List in InfoList)
                    {
                        RadComboBoxItem item = new RadComboBoxItem();

                        item.Text = List.Name + " " + List.Amphurs.Name + " " + List.Amphurs.Provinces.Name;
                        item.Value = List.Sequence.ToString();

                        item.Attributes.Add("District", List.Name);
                        item.Attributes.Add("Amphurs", List.Amphurs.Name);
                        item.Attributes.Add("Provinces", List.Amphurs.Provinces.Name);

                        ctrChild.Items.Add(item);
                        item.DataBind();
                    }
                    ctrChild.SelectedValue = string.Empty;
                    ctrChild.Focus();
                }
            }
        }
    }
}